#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main(){

    pid_t id = fork();  // fork() 之后的代码父子进程是共享的！

    if( id < 0 ){
        // create process fail
        perror("fail");
        return 1;
    }
    else if( id == 0 ){
        // child process task
        while(1){
            printf("I am child process : pid : %d ; ppid : %d;\n",getpid(), getppid());
            sleep(1);
        }
    }
    else{ 
        // father process task
        while(1){
            printf("I am father process : pid : %d ; ppid : %d;\n",getpid(), getppid());
            sleep(1);
        }
    }
    return 0;
}
